package Hashtable;

import java.util.HashSet;
import java.util.Set;

/**
 * @ Author     ：侯耀祖
 * @ Description：
 */
public class isHappy {
    public int getSum(int n){
        int sum = 0;
        while (n > 0){
            int temp = n % 10;
            sum += temp * temp;
            n /= 10;
        }
        return sum;
    }
    public boolean isHappy(int n) {
        Set<Integer> set = new HashSet<>();
        while (n != 1 && !set.contains(n)){
            set.add(n);
            n = getSum(n);
        }
        return n == 1;
    }
}
